<!DOCTYPE html>
<html>
<head>
  <title>力力钱包-无卡支付</title>
  <meta charset="utf-8">
  <meta http-equiv="pragma" content="no-cache">
  <meta http-equiv="cache-control" content="no-cache">
  <meta http-equiv="expires" content="0">
  <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
  <meta http-equiv="description" content="This is my page">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
  <link rel="stylesheet" href="http://demo.open.weixin.qq.com/jssdk/css/style.css">
  <script type="text/javascript" src="http://res.wx.qq.com/open/js/jweixin-1.1.0.js"></script>
  <script type="text/javascript" src="../js/jquery-1.8.3.js"></script>
  <script type="text/javascript" src="../js/layer/layer.js"></script>
</head>
<style>
html{margin:0 auto;}
</style>
<body style="width: 90%; margin-left: 5%;margin-top:20px;">
	<div style="text-align:left; margin-bottom:2em; color: #33B1E1;">
		<span>如果您还未关注我们，长按下方二维码关注我们！</span><br>
		<span>如果您已经关注，<span style="color:red;">点击右上角</span>，把我们的公众号分享给微信好友，您的费率最低可以降至0.0039!</span><br>
		<span>联系我们：4007676922</span>
	</div>
	<div id="qrcode"><img src="" style="width:50%; margin-left:25%;"></div>
	
</body>
<script type="text/javascript">
 	var openID;
	$(function(){
		openID = GetQueryString("openID");
		var index = layer.load(0);
		$.ajax({
			url : '../api/getQrcode',
			type : 'post',
			data : {
				'openID' : openID
			},
			success : function(res){
				$("#qrcode img").attr("src", res);
			},
			error : function(){
				layer.msg("二维码加载失败，暂时无法分享");
			}
		})
		$.ajax({
			url : '../jssdk/index',
			type : 'post',
			data : {
				'signurl' : location.href.split("#")[0]
			},
			success : function(res){
				layer.close(index);
				wx.config({
					  debug: false,
				      appId: res.appId,
				      timestamp: res.timestamp,
				      nonceStr: res.nonceStr,
				      signature: res.signature,
				      jsApiList: [
				        'checkJsApi',
				        'onMenuShareTimeline',
				        'onMenuShareAppMessage'
				      ]
				  });
			},
			error:function(){
				layer.close(index);
			}
		});
		
		wx.ready(function () {
			//分享给朋友
		    wx.onMenuShareAppMessage({
		      title: '力力钱包-无卡支付',
		      desc: '力力钱包-无卡支付，推荐好友费率最低降至0.0039，行动起来吧！',
		      link: 'http://www.lilishuju.com/front/share.html?openID=' + openID,
		      imgUrl: 'http://www.lilishuju.com/img/subscribe.jpg',
		      success: function (res) {
		    	  layer.msg("已分享");
		      },
		      cancel: function (res) {
		    	  layer.msg("已取消");
		      }
		    });

		    //分享到朋友圈
		    wx.onMenuShareTimeline({
		      title: '力力钱包-无卡支付',
		      link: 'http://www.lilishuju.com/front/share.html?openID=' + openID,
		      imgUrl: 'http://www.lilishuju.com/img/subscribe.jpg',
		      success: function (res) {
		    	  var index1 = layer.load(0);
		    	  $.ajax({
						url : '../llPay/share',
						type : 'post',
						data : {
							'openID' : openID
						},
						success : function(res){
							layer.close(index1);
							if(res == 'success' || res == "分享成功"){
								layer.msg("已分享到朋友圈");
							}else{
								layer.msg("已分享，交易服务器错误：" + res);
							}
							
						},
						error : function(){
							layer.close(index1);
							layer.msg("已分享！");
						}
					})
		          	
		      },
		      cancel: function (res) {
		    	  layer.msg("已取消");
		      }
		    });
		});

		wx.error(function (res) {
			layer.msg(res.errMsg);
		});
	})
	
	/* 获取url后的字符串 */
    function GetQueryString(name) {
        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
        var r = window.location.search.substr(1).match(reg);
        if (r != null) {
            return (r[2]);
        }
        return null;
    }
</script>
</html>